//
//  GJSUtilHTTPRequestClient.h
//  YuanXinTrack
//
//  Created by GJS on 2018/5/15.
//  Copyright © 2018年 GJS. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol GJSOAuthInfoObserver <NSObject>

//网络请求401时处理
- (void)onUnauthorized;

@end

@class GJSOAuthCredential;

@interface GJSUtilHTTPRequestClient : NSObject

@property (nonatomic, copy) NSString *userName;
@property (nonatomic, copy) NSString *password;

@property (readwrite, nonatomic, strong) NSURL    * baseURL;
@property (readwrite, nonatomic, strong) NSString * clientID;
@property (readwrite, nonatomic, strong) NSString * clientSecret;

/**
 * 默认超时时间
 */
@property (readwrite, assign, nonatomic) NSTimeInterval timeoutInterval;

+ (instancetype)shareInstance;

//添加对OAuth 服务状态管理
- (void)addOAuthInfoObserver:(id<GJSOAuthInfoObserver>)oauthObserver;

//移除当前OAuth 服务状态管理
- (void)removeOAuthInfoObserver:(id<GJSOAuthInfoObserver>)oauthObserver;

//还原网络请求的身份信息
- (BOOL)retrieveCredentialWithIdentifier:(NSString *)identifier;

- (NSURLSessionTask *)authenticateUsingOAuthWithURLString:(NSString *)URLString
                                                 username:(NSString *)username
                                                 password:(NSString *)password
                                                    scope:(NSString *)scope
                                                  success:(void (^)(GJSOAuthCredential *credential))success
                                                  failure:(void (^)(NSError *error))failure;

- (NSURLSessionTask *)authenticateUsingOAuthWithURLString:(NSString *)URLString
                                               parameters:(NSDictionary *)parameters
                                                  success:(void (^)(id responseObject))success
                                                  failure:(void (^)(NSError *error))failure;

- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
                            parameters:(nullable id)parameters
                               success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                               failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure DEPRECATED_ATTRIBUTE;

- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
                            parameters:(nullable id)parameters
                              progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress
                               success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                               failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;

- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
                             parameters:(nullable id)parameters
                                success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                                failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure DEPRECATED_ATTRIBUTE;

- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
                             parameters:(nullable id)parameters
                               progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
                                success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                                failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;

- (NSURLSessionDataTask *)uploadMultiPart:(NSString *)URLString
                               parameters:(id)parameters
                                     data:(NSData *)data
                                  success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                  failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure DEPRECATED_ATTRIBUTE;

- (NSURLSessionDataTask *)uploadMultiPart:(NSString *)URLString
                               parameters:(id)parameters
                                     data:(NSData *)data
                                 progress:(nullable void (^)(NSProgress * _Nonnull))uploadProgress
                                  success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                  failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

- (NSURLSessionDataTask *)uploadFile:(NSString *)URLString
                                data:(NSData *)data
                             headers:(NSDictionary *)headers
                             success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                             failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure DEPRECATED_ATTRIBUTE;

- (NSURLSessionDataTask *)uploadFile:(NSString *)URLString
                                data:(NSData *)data
                             headers:(NSDictionary *)headers
                            progress:(nullable void (^)(NSProgress * _Nonnull))uploadProgress
                             success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                             failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

- (NSURLSessionDownloadTask *)downloadFile:(NSString *)URLString
                          headerAccept:(NSString *)headerAccept
                              cacheURL:(NSURL *)cacheUrl
                      downloadProgress:(void (^)(NSProgress *downloadProgress))downloadProgressBlock
                               success:(void (^)(NSURLSessionDownloadTask *task, id responseObject))success
                               failure:(void (^)(NSURLSessionDownloadTask *task, NSError *error))failure;

@end
